package test.udp;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;

public class UDPServerHandler extends IoHandlerAdapter {

  private UDPServer server;

  public UDPServerHandler(UDPServer server) {
    this.setServer(server);
  }
  
  
  public UDPServerHandler() {
  }

  public void setServer(UDPServer server) {
    this.server=server;
  }

  public UDPServer getServer() {
    return server;
  }

  @Override
  public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
    // TODO Auto-generated method stub
    super.exceptionCaught(session, cause);
  }

  @Override
  public void messageReceived(IoSession session, Object message) throws Exception {
    if(message instanceof IoBuffer){
      System.out.println("ioBuffer");
      IoBuffer buf=(IoBuffer)message;
      if(buf.hasRemaining()){
        int i=buf.getInt();
        System.out.println(i);
      }
    }
  }

  @Override
  public void messageSent(IoSession session, Object message) throws Exception {
    // TODO Auto-generated method stub
    super.messageSent(session, message);
  }

  @Override
  public void sessionClosed(IoSession session) throws Exception {
    // TODO Auto-generated method stub
    super.sessionClosed(session);
  }

  @Override
  public void sessionCreated(IoSession session) throws Exception {
    // TODO Auto-generated method stub
    super.sessionCreated(session);
  }

  @Override
  public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
    // TODO Auto-generated method stub
    super.sessionIdle(session, status);
  }

  @Override
  public void sessionOpened(IoSession session) throws Exception {
    // TODO Auto-generated method stub
    super.sessionOpened(session);
  }
}
